MenuSelect
MenuSelect Initiate user selection of a menu item
#include <Menus.h> Menu Manager
long MenuSelect(startPt );
Point startPt ; mouse position in global coordinates
returns HiWord is menu ID or 0; LoWord is item number
MenuSelect initiates interactive selection from a menu. Call this when a
mouseDown event indicates inMenuBar. The user selects from the menu and
this function returns a code indicating which item was selected.
startPt is the position (in global coordinates) of a mouse-down event that
returns a value of inMenuBar. Typical usage is to pass
EventRecord.where, exactly as obtained via GetNextEvent.
Returns: a 32-bit long that indicates the selected menu and item. It is made
up of two values as follows:
High Word menu ID of selection (0 means none)
Low Word item number of selection

Notes: This function leaves the selected menu title highlighted in the menu bar and
you must explicitly call HiliteMenu(0) to set it back to normal. For
lengthy operations, applications normally set the cursor to a watch (see
SetCursor) and leave the menu highlighted until the operation is
finished.
When the high word is 0, the low word is un defined. This happens when
the user releases the mouse outside of a menu, on a disabled item, on a
submenu title, or when the menu is owned by a DA. You may call
MenuChoice to see which of these "null choices" was selected.
About DAs: Menus with negative IDs are owned by DAs. When one of
these is selected, the return value is sent to the DA and you get a "cancel
value (the high word is 0).
When the return code indicates an item from the menu, use GetItem to
learn the DA's name and use OpenDeskAcc to give control to the DA.
Use MenuKey after getting a command-shifted key-down event. This
function looks through the menus and finds which selection (if any) is
equivalent to the keystroke.
Use PopUpMenuSelect when a user clicks in a "popup box" or "popup
menu title rectangle" indicating the desire to select from items in that menu.
Example
#include <Menus.h>
#include Í/* defines inMenuBar */
#include Í/* defines event record and constants */
EventRecord myEvent;
short wPart;
long menuResult;
WindowPtr whichWindow, myWindow;
/* ... fragment of a main event loop ... */
if ( GetNextEvent( everyEvent, &myEvent ) ) {
switch ( myEvent.what ) {
case mouseDown:
wPart = FindWindow( myEvent.where, & whichWindow );
if ( (wPart==inMenuBar) ) {
menuResult = MenuSelect( myEvent.where );
if ( HiWord( menuResult != 0 ) ) { /* cancelled or DA? */
doCommand( menuResult ); /* no, do it */
HiliteMenu( 0 ); /* always clean up */
}
break;
}
else if (wPart=inGoAway) { ... etc ... }
case keyDown:
/*. ... etc ... */
}
}